package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDTO;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.NursingProjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 护理模块的业务层
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageResponse selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        NursingProject nursingProject = NursingProject.builder().name(name).status(status).build();
        Page<NursingProjectVO> nursingProjects = nursingProjectMapper.list(nursingProject);
        return PageResponse.of(nursingProjects,NursingProjectVO.class);
    }

    /**
     * 添加护理
     * @param nursingProjectDTO
     */
    @Override
    public void add(NursingProjectDTO nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDTO, NursingProject.class);
        nursingProjectMapper.add(nursingProject);
    }

    /**
     * 根据id查询护理
     * @param id
     * @return
     */
    @Override
    public NursingProjectVO getByIdWithNursing(Integer id) {
        NursingProject nursingProject= nursingProjectMapper.getByIdWithNursing(id);
        NursingProjectVO nursingProjectVO = BeanUtil.toBean(nursingProject, NursingProjectVO.class);
        return nursingProjectVO;
    }

    /**
     * 修改护理
     * @param nursingProjectDTO
     */
    @Override
    public void updateNursing(NursingProjectDTO nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDTO, NursingProject.class);

        nursingProjectMapper.updateNursing(nursingProject);
    }

    /**
     * 修改状态
     * @param id
     * @param status
     */
    @Override
    public void changeStatusById(Integer id, Integer status) {

        nursingProjectMapper.changeStatusById(id,status);
    }

    /**
     * 删除护理
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        nursingProjectMapper.deleteById(id);
    }

    /**
     * 状态修改
     * @param id
     * @param status
     */
    @Override
    public void startOrStop(Integer id, Integer status) {
        nursingProjectMapper.startOrStop(id,status);
    }
}
